﻿using System;
using System.Collections.Generic;

namespace _1389_create_target_array_in_the_given_order
{
    class Program
    {
        static void Main (string[] args)
        {
            int[] nums = new int[] { 4, 3, 2, 1, 0 };
            int[] index = new int[] { 0, 1, 2, 3, 0 };
            index = CreateTargetArray (nums, index);
            for (int i = 0;i < index.Length;i++)
            {
                Console.Write (index[i] + " ");
            }
        }

        public static int[] CreateTargetArray (int[] nums, int[] index)
        {
            int[] target = new int[nums.Length];
            for (int i = 0;i < index.Length;i++)
            {
                target = SortArray (target, index[i], nums[i]);
            }

            return target;
        }

        static int[] SortArray (int[] nums, int count, int number)
        {
            for (int i = 0;i < nums.Length;i++)
            {
                if (i == count)
                {
                    int num = nums[i];
                    nums[i] = number;
                    number = num;
                    count++;
                }
            }
            return nums;
        }
    }
}
